---
apiVersion: v1
kind: ConfigMap
metadata:
  name: wrk-config
  namespace: px-protocol-loadtest
data:
  wrk.lua: |
    wrk.method = "POST"
    wrk.body   = "{\"body_size\":12288, \"header_size\":1024, \"chunk_size\":12288}"
    wrk.headers["Content-Type"] = "application/json"

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: wrk
  namespace: px-protocol-loadtest
spec:
  replicas: 1
  selector:
    matchLabels:
      name: wrk
  template:
    metadata:
      labels:
        name: wrk
    spec:
      initContainers:
      - name: server-wait
        # yamllint disable-line rule:line-length
        image: gcr.io/pixie-oss/pixie-dev-public/curl:multiarch-7.87.0@sha256:f7f265d5c64eb4463a43a99b6bf773f9e61a50aaa7cefaf564f43e42549a01dd
        # yamllint disable rule:indentation rule:line-length
        command: ['sh', '-c', 'set -xe;
          URL="${PROTOCOL}://${SERVICE_NAME}:${SERVICE_PORT}${HEALTH_PATH}";
          until [ $(curl -m 0.5 -s -o /dev/null -w "%{http_code}" -X POST -H "Content-Type: application/json" --data {} ${URL}) -eq 200 ]; do
            echo "waiting for ${URL}";
            sleep 2;
          done;']
        # yamllint enable rule:indentation rule:line-length
        env:
        - name: SERVICE_NAME
          value: "server"
        - name: SERVICE_PORT
          value: "8080"
        - name: HEALTH_PATH
          value: ""
        - name: PROTOCOL
          value: "http"
      containers:
      - name: app
        image: gcr.io/pixie-oss/pixie-dev/src/e2e_test/protocol_loadtest/http/wrk:latest
        # yamllint disable rule:indentation rule:line-length
        command: ['sh', '-c', 'set -xe;
          while true; do
            wrk -t${NUM_THREADS} -c${NUM_CONNECTIONS} -d${DURATION} -s/config/wrk.lua http://${SERVICE_NAME}:${SERVICE_PORT};
          done;']
        # yamllint enable rule:indentation rule:line-length
        env:
        - name: SERVICE_NAME
          value: "server"
        - name: SERVICE_PORT
          value: "8080"
        - name: NUM_CONNECTIONS
          value: "10"
        - name: NUM_THREADS
          value: "10"
        # duration doesn't really matter because the load generator is called in a loop.
        - name: DURATION
          value: "1m"
        volumeMounts:
        - name: config-volume
          mountPath: /config
      volumes:
      - name: config-volume
        configMap:
          name: wrk-config
